<template>
  <div class="wbox">
    <div style="margin-top: 30px">
      <div>
        <div v-if="imageUrl" style="margin-bottom: 10px">
          <img :src="imageUrl" alt="Thumbnail" style="width: 100px; height: 100px" />
        </div>
        <a-upload
          :before-upload="beforeUpload"
          :show-upload-list="false"
          :multiple="false"
          :max-count="1"
          :file-list="fileList"
          @change="handleChange"
        >
          <a-button> 点击上传 </a-button>
        </a-upload>
      </div>
    </div>
    <div id="components-form-demo-advanced-search">
      <a-form :model="formState" :label-col="{ span: 8 }" :wrapper-col="{ span: 16 }">
    <a-row :gutter="[16, 16]">
      <a-col v-for="(item, index) in fields" :key="index" :span="8" :style="{ marginBottom: '0px' }">
        <a-form-item :label="item.label" :required="item.required">
          <component :is="item.component" v-if="editable" v-bind="item.props" @change="handleInputChange(item.name, $event)" />
          <div v-else>{{ formState[item.name] }}</div>
        </a-form-item>
      </a-col>
    </a-row>
  </a-form>
    </div>
    <div>
      <a-button @click="toggleEditable" style="margin-top: 30px">编辑</a-button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fileDetails: [
        {
          imgUrl: 'https://static.jeecg.com/upload/test/3a4490d5d1cd495b826e528537a47cc1.jpg',
        },
      ],
      expand: false,
      editable: false,
      form: this.$form.createForm(this, {
        personCode: '1111',
      }),
      fields: [
        { name: 'personCode', label: '人员编码', component: 'a-input', props: { placeholder: '请输入人员编码' }, required: true },
        { name: 'name', label: '姓名', component: 'a-input', props: { placeholder: '请输入姓名' }, required: true },
        { name: 'gender', label: '性别', component: 'a-select', props: { options: [{ value: '1', label: '男' }, { value: '2', label: '女' }] }, required: true },
        { name: 'age', label: '年龄', component: 'a-input-number', props: { placeholder: '请输入年龄' }, required: true },
        { name: 'birthDate', label: '出生年月', component: 'a-date-picker', props: {}, required: true },
        { name: 'ethnicity', label: '民族', component: 'a-input', props: { placeholder: '请输入民族' }, required: true },
        { name: 'idNumber', label: '身份证号码', component: 'a-input', props: { placeholder: '请输入身份证号码' }, required: true },
        { name: 'politicalStatus', label: '政治面貌', component: 'a-input', props: { placeholder: '请输入政治面貌' }, required: true },
        { name: 'education', label: '学校学历专业', component: 'a-input', props: { placeholder: '请输入学校学历专业' }, required: true },
        { name: 'fullTimeEducation', label: '全日制', component: 'a-input', props: { placeholder: '请输入全日制学历' }, required: true },
        { name: 'nonFullTimeEducation', label: '非全日制', component: 'a-input', props: { placeholder: '请输入非全日制学历' }, required: true },
        { name: 'title', label: '职称', component: 'a-input', props: { placeholder: '请输入职称' }, required: true },
        { name: 'nativePlace', label: '籍贯', component: 'a-input', props: { placeholder: '请输入籍贯' }, required: true },
        { name: 'address', label: '家庭住址', component: 'a-input', props: { placeholder: '请输入家庭住址' }, required: true },
        { name: 'hukou', label: '户籍所在地', component: 'a-input', props: { placeholder: '请输入户籍所在地' }, required: true },
        { name: 'maritalStatus', label: '婚姻状况', component: 'a-select', props: { options: [{ value: '1', label: '已婚' }, { value: '2', label: '未婚' }] }, required: true },
        { name: 'phoneNumber', label: '电话号码', component: 'a-input', props: { placeholder: '请输入电话号码' }, required: true },
        { name: 'shortNumber', label: '短号', component: 'a-input', props: { placeholder: '请输入短号' }, required: true },
        { name: 'vehicleInfo', label: '车辆情况', component: 'a-input', props: { placeholder: '请输入车辆情况' }, required: true },
        { name: 'recruitmentMethod', label: '招录方式', component: 'a-input', props: { placeholder: '请输入招录方式' }, required: true },
      ],
      fieldsno: [
        { name: 'personCode', label: '人员编码', props: { placeholder: '请输入人员编码' } },
        { name: 'name', label: '姓名', props: { placeholder: '请输入姓名' } },
        { name: 'gender', label: '性别', props: { options: [{ value: 'male', label: '男' }, { value: 'female', label: '女' }] } },
        { name: 'age', label: '年龄', props: { placeholder: '请输入年龄' } },
        { name: 'birthDate', label: '出生年月', props: {} },
        { name: 'ethnicity', label: '民族', props: { placeholder: '请输入民族' } },
        { name: 'idNumber', label: '身份证号码', props: { placeholder: '请输入身份证号码' } },
        { name: 'politicalStatus', label: '政治面貌', props: { placeholder: '请输入政治面貌' } },
        { name: 'education', label: '学校学历专业', props: { placeholder: '请输入学校学历专业' } },
        { name: 'fullTimeEducation', label: '全日制', props: { placeholder: '请输入全日制学历' } },
        { name: 'nonFullTimeEducation', label: '非全日制', props: { placeholder: '请输入非全日制学历' } },
        { name: 'title', label: '职称', props: { placeholder: '请输入职称' } },
        { name: 'nativePlace', label: '籍贯', props: { placeholder: '请输入籍贯' } },
        { name: 'address', label: '家庭住址', props: { placeholder: '请输入家庭住址' } },
        { name: 'hukou', label: '户籍所在地', props: { placeholder: '请输入户籍所在地' } },
        { name: 'maritalStatus', label: '婚姻状况', props: { options: [{ value: '1', label: '已婚' }, { value: '2', label: '未婚' }] } },
        { name: 'phoneNumber', label: '电话号码', props: { placeholder: '请输入电话号码' } },
        { name: 'shortNumber', label: '短号', props: { placeholder: '请输入短号' } },
        { name: 'vehicleInfo', label: '车辆情况', props: { placeholder: '请输入车辆情况' } },
        { name: 'recruitmentMethod', label: '招录方式', props: { placeholder: '请输入招录方式' } },
      ],
      fileList: [],
      imageUrl: '',
      fields: [
        { name: 'personCode', label: '人员编码', component: 'AInput', props: { placeholder: '请输入人员编码' }, required: true },
        { name: 'name', label: '姓名', component: 'AInput', props: { placeholder: '请输入姓名' }, required: true },
        { name: 'gender', label: '性别', component: 'ASelect', props: { options: [{ value: '1', label: '男' }, { value: '2', label: '女' }] }, required: true },
        { name: 'age', label: '年龄', component: 'AInputNumber', props: { placeholder: '请输入年龄' }, required: true },
        { name: 'birthDate', label: '出生年月', component: 'ADatePicker', props: {}, required: true },
        { name: 'ethnicity', label: '民族', component: 'AInput', props: { placeholder: '请输入民族' }, required: true },
        { name: 'idNumber', label: '身份证号码', component: 'AInput', props: { placeholder: '请输入身份证号码' }, required: true },
        { name: 'politicalStatus', label: '政治面貌', component: 'AInput', props: { placeholder: '请输入政治面貌' }, required: true },
        { name: 'education', label: '学校学历专业', component: 'AInput', props: { placeholder: '请输入学校学历专业' }, required: true },
        { name: 'fullTimeEducation', label: '全日制', component: 'AInput', props: { placeholder: '请输入全日制学历' }, required: true },
        { name: 'nonFullTimeEducation', label: '非全日制', component: 'AInput', props: { placeholder: '请输入非全日制学历' }, required: true },
        { name: 'title', label: '职称', component: 'AInput', props: { placeholder: '请输入职称' }, required: true },
        { name: 'nativePlace', label: '籍贯', component: 'AInput', props: { placeholder: '请输入籍贯' }, required: true },
        { name: 'address', label: '家庭住址', component: 'AInput', props: { placeholder: '请输入家庭住址' }, required: true },
        { name: 'hukou', label: '户籍所在地', component: 'AInput', props: { placeholder: '请输入户籍所在地' }, required: true },
        { name: 'maritalStatus', label: '婚姻状况', component: 'ASelect', props: { options: [{ value: '1', label: '已婚' }, { value: '2', label: '未婚' }] }, required: true },
        { name: 'phoneNumber', label: '电话号码', component: 'AInput', props: { placeholder: '请输入电话号码' }, required: true },
        { name: 'shortNumber', label: '短号', component: 'AInput', props: { placeholder: '请输入短号' }, required: true },
        { name: 'vehicleInfo', label: '车辆情况', component: 'AInput', props: { placeholder: '请输入车辆情况' }, required: true },
        { name: 'recruitmentMethod', label: '招录方式', component: 'AInput', props: { placeholder: '请输入招录方式' }, required: true },
      ],
      formState: {
        personCode: '',
        name: '',
        gender: '',
        age: '',
        birthDate: '',
        ethnicity: '',
        idNumber: '',
        politicalStatus: '',
        education: '',
        fullTimeEducation: '',
        nonFullTimeEducation: '',
        title: '',
        nativePlace: '',
        address: '',
        hukou: '',
        maritalStatus: '',
        phoneNumber: '',
        shortNumber: '',
        vehicleInfo: '',
        recruitmentMethod: '',
      }
    };
  },
  methods: {
    handleInputChange(fieldName, value) {
      this.formState[fieldName] = value;
    },
    toggleEditable() {
      this.editable = !this.editable;
    },
    beforeUpload(file) {
      // Add your validation logic for file upload here
      return true;
    },
    handleChange(info) {
      if (info.file.status === 'done') {
        this.imageUrl = info.file.response.url; // Assuming the response contains the URL
        this.fileList = info.fileList;
      }
    },
    handleSearch(e) {
      e.preventDefault();
      // Handle search logic here
    },
    getOptionLabel(name, options, value) {
      const option = options.find(option => option.value === value);
      return option ? option.label : '';
    },
  },
};
</script>

<style scoped>
.wbox {
  display: flex;
}
/* .ant-advanced-search-form {
  padding: 24px;
  border-radius: 6px;
} */

/* .ant-advanced-search-form .ant-form-item {
  display: flex;
} */

/* .ant-advanced-search-form .ant-form-item-control-wrapper {
  flex: 1;
} */

#components-form-demo-advanced-search .ant-form {
  max-width: none;
}
#components-form-demo-advanced-search .search-result-list {
  margin-top: 16px;
  border: 1px dashed #e9e9e9;
  border-radius: 6px;
  background-color: #fafafa;
  text-align: center;
  padding-top: 80px;
}
/* 样式可以根据需要调整 */
img {
  display: block;
  margin: 0 auto;
}
</style>

